import {https} from "@/utils/request";
import {
    CreatePermissionFormProp,
    PermissionInfoProp,
    PermissionListProp,
    PermissionTreeProp,
    UpdatePermissionFormProp
} from "@/pages/authority/modules";

// permissionTree 获取资源
export const permissionTree = (pId = 0, all = false): Promise<PermissionTreeProp[]> => {
    return https.request({
        url: '/authority/permission/tree',
        method: 'get',
        params: {pId: pId, all: all}
    })
}

// permissionList 资源列表
export const permissionList = (pId = 0): Promise<PermissionListProp[]> => {
    return https.request({
        url: '/authority/permission/list',
        method: 'get',
        params: {pId: pId}
    })
}

// permissionCreate 创建
export const permissionCreate = (data: CreatePermissionFormProp): Promise<PermissionListProp> => {
    return https.request({
        url: '/authority/permission/create',
        method: 'post',
        data: data
    })
}

// permissionUpdate 更新
export const permissionUpdate = (data: UpdatePermissionFormProp): Promise<PermissionListProp> => {
    return https.request({
        url: '/authority/permission/update',
        method: 'post',
        data: data
    })
}

// permissionList 资源列表
export const permissionInfo = (pId: number): Promise<PermissionInfoProp> => {
    return https.request({
        url: '/authority/permission/info',
        method: 'get',
        params: {pId: pId}
    })
}